package com.geyue.controller;

import com.geyue.common.toolbox.result.Res;
import com.geyue.core.model.Admin;
import com.geyue.core.model.Help;
import com.geyue.core.service.HelpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Created by Lyon on 2017/6/7.
 */
@Controller
@RequestMapping("/help")
public class HelpController {

    @Autowired
    private HelpService helpService;

    @RequestMapping(value = "/",method = RequestMethod.GET)
    public String list(HttpSession session, Model model){
        Admin admin = (Admin) session.getAttribute("admin");

        if(admin == null)
            return "error";

        return "help/list";
    }

    @RequestMapping(value = "/page", method = RequestMethod.POST)
    @ResponseBody
    public Res index(Help help, Integer pageSize, Integer pageNum, HttpSession session) {
        Admin admin = (Admin) session.getAttribute("admin");

        if(admin == null)
            return Res.fail("登录信息过时,请重新登录!");

        return Res.success("", helpService.getPage(pageNum, pageSize, help));
    }

}
